﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xenta.Operations;
using Xenta.Utils;

namespace Xenta.Tests.Operations
{
    [TestFixture]
    public class SalesOptionTranslationTests : OperationTest
    {
        protected override IEnumerable<Type> ModelMappings
        {
            get
            {
                return NHMappings.ALL;
            }
        }

        [TestCase("name", "value")]
        public void Can_CRUD(string name, string value)
        {
            var t_option = Processor.Execute(new CreateSalesOptionTranslation
            {
                HolderID = Processor.Execute(new CreateSalesOption
                {
                    CodeName = "xy",
                    CodeValue = "xy",
                }).Result.EntityID,
                LanguageID = Processor.Execute(new CreateLanguage
                {
                    Code = "xy"
                }).Result.EntityID,
                Name = name,
                Value = value
            }).Result;

            Assert.NotNull(t_option);
            t_option.Name.AreEqualIgnoringCase(name);
            t_option.Value.AreEqualIgnoringCase(value);
            t_option.AreEqual(Processor.Execute(new GetSalesOptionTranslation
            {
                EntityID = t_option.EntityID
            }).Result);

            name = name.Reverse();
            value = value.Reverse();
            var upd_t_option = Processor.Execute(new UpdateSalesOptionTranslation
            {
                EntityID = t_option.EntityID,
                LanguageID = t_option.Language.EntityID,
                Name = name,
                Value = value
            }).Result;

            Assert.NotNull(upd_t_option);
            upd_t_option.AreEqual(t_option);
            upd_t_option.Name.AreEqualIgnoringCase(name);
            upd_t_option.Value.AreEqualIgnoringCase(value);

            Processor.Execute(new DeleteSalesOptionTranslation
            {
                EntityID = t_option.EntityID
            });
        }
    }
}
